module.exports = function (grunt) {

    require('load-grunt-tasks')(grunt);

    require('time-grunt')(grunt);

    grunt.initConfig({
        //合并
        concat: {
            js: {
                src: ['source_js/*.js'],
                dest: 'js/demo.js'
            },
            css:{
                src: ['css/*.css'],
                dest:'css/main.css'
            }
        },
        //js验证
        jshint: {
            src: ['source_js/*.js']
        },
        //js压缩合并
        uglify: {
            files: {
                src: ['js/demo.js'],
                dest: 'js/demo.min.js'
            }
        },
        //less
        less: {
            demo: {
                src: ['source_css/demo_1.less'],
                dest: 'css/demo.css'
            },
            bootstrap: {
                src: ['source_css/less/bootstrap.less'],
                dest: 'css/bootstrap.css'
            }
        },
        //css压缩
        cssmin: {
            demo: {
                src: ['css/demo.css'],
                dest: 'css/demo.min.css'
            },
            bootstrap: {
                src: ['css/bootstrap.css'],
                dest: 'css/bootstrap.min.css'
            }
        },
        //删除
        clean: {
            css: ["css/demo.css","css/bootstrap.css"],
            js: ["js/demo.js"],
            all:["css/*.css","js/*.js","img/*.png"],
            test:["test/*"]
        },
        //监听
        watch: {
            files: ['source_css/*.less'],
            tasks: ['less:demo']
        },
        //复制
        copy: {
            test: {
                expand: true,
                src: ['css/*.min.css','js/*.min.js'],
                dest: 'test/'
            }
        },
        //shell命令
        shell: {
            ls: {
                command: function (arg) {
                    return 'ls ' + arg;
                }
            },
            gulp: {
                command: function (arg){
                    return 'sudo gulp '+ arg;
                }
            }
        },
        //图片合并
        sprite:{
            all: {
                src: 'source_img/*.png',
                dest: 'img/sprites.png',
                destCss: 'css/sprites.css'
            }
        },
        webpack:{
            test: {
                entry: "./source_js/demo_1.js",
                output: {
                    path: "js/",
                    filename: "webpack.js"
                }
            }
        }
    });

    grunt.registerTask('jss',['concat:js']);

    grunt.registerTask('js_uglify', ['jss','uglify','clean:js']);

    grunt.registerTask('less_css', ['less']);

    grunt.registerTask('min_css',['less_css','cssmin','clean:css']);

    grunt.registerTask('build',['clean:all','js_uglify','min_css']);

    grunt.registerTask('build_test',['clean:test','copy:test']);

    grunt.registerTask('ls',['shell:ls:-al']);
}

